/**
 * * 自动注册全局组件
 */
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'

const requireComponent = require.context('./', true, /[A-Z]\w+\.vue$/)

const components = requireComponent.keys().reduce((total, fileName) => {
  // 获取组件配置
  const componentConfig = requireComponent(fileName)

  // 获取组件的 PascalCase 命名
  const componentName = upperFirst(
    camelCase(
      fileName
        .split('/')
        .pop()
        .replace(/\.\w+$/, '')
    )
  )

  total[componentName] = componentConfig.default || componentConfig

  return total
}, {})

export default components
